import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LKQ
 * @date 2022/2/21 17:21
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {2,3,1,3,2};
        solution.frequencySort(nums);
    }
    public int[] frequencySort(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i: nums) {
            map.put(i, map.getOrDefault(i, 0) + 1);

        }
        int n = nums.length;
        int[][] ans = new int[n][2];
        for (int i = 0; i < n; i++) {
            ans[i][0] = nums[i];
            ans[i][1] = map.get(nums[i]);
        }
        Arrays.sort(ans, (a, b)-> {
            if (a[1] != b[1]) {
                return a[1] - b[1];
            }else {
                return b[0] - a[0];
            }
        });
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ans[i][0];
        }
        return res;
    }
}
